<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style>
			.bg{
				background: red;
			}
		</style>
	</head>
	<body>
		<table>
			<tr class="bg"><td>1</td></tr>
			<tr><td>2</td></tr>
			<tr class="bg"><td>3</td></tr>
			<tr><td>4</td></tr>
			<tr class="bg"><td>5</td></tr>
		</table>
		
<script>
	var str = '';
	var className = '';
	str += '<table>';
	for(var i=1;i<=5;i++){
		className = i%2==0 ? '' : ' class="bg" ';
		str += '<tr'+className+'><td>'+i+'</td></tr>';
	}
	str +='</table>';
	alert(str);
	document.write(str);
</script>
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	</body>
</html>
